﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace SportingGoodsExhibitionSystem
{
    /// <summary>
    /// FunctionThree.xaml 的交互逻辑
    /// </summary>
    public partial class FunctionThree : Page
    {
        public FunctionThree()
        {
            InitializeComponent();
        }
        string strCon = Properties.Resources.strCON;
        int stuNum;
        public DataTable GetDataByNum()
        {
            
            SqlConnection con = new SqlConnection(strCon);
            con.Open();
            SqlCommand cmd = new SqlCommand("select studentId as '学号',studentNa as '姓名', studentCollege as '学院' , reason as '请假原因', time as '请假时长', data as '请假时间' from vacation where studentId=@Id and status<>2 ", con);
            cmd.Parameters.Add("@Id", SqlDbType.VarChar, 50).Value = stuNum;

            //获取查询结果
            //SqlDataReader
            SqlDataAdapter read = new SqlDataAdapter(cmd);
            //保存查询结果
            DataTable dt = new DataTable();
            read.Fill(dt);
            return dt;
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            SqlConnection con = new SqlConnection(strCon);
            con.Open();
      

            SqlCommand cmd = new SqlCommand("select * from studentInfo where studentStatus=@num ",con);
            cmd.Parameters.Add("@num", SqlDbType.Int, 10).Value = 1;
            SqlDataAdapter read = new SqlDataAdapter(cmd);
            //DataTable dt = new DataTable();
            DataSet dataset = new DataSet();
            read.Fill(dataset);
            DataTable table = dataset.Tables[0];
            DataTable dt = new DataTable();
            DataRowCollection rows = table.Rows;
            DataRow row = rows[0];
            
                stuNum = Convert.ToInt32(row["studentNumber"].ToString());    
                dt = GetDataByNum();
                dataTable.ItemsSource = dt.DefaultView;

            
        }
    }
}
